﻿/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Windows Forms Controls Class Library
 * Version 2.00
 * 
 * Ok-Cancel Button Panel Class
 *      Provides a panel-style bar with an OK and Cancel button.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Adaptive.Foundation.Windows.Forms
{
    /// <summary>
    /// Provides a panel-style bar with an OK and Cancel button.
    /// </summary>
    /// <remarks>
    /// This is intended for use with common modal dialogs that use OK and Cancel buttons.
    /// </remarks>
    [Browsable(true), ToolboxItem(true)]
    public partial class OkCancelButtonPanel : UserControl
    {
        /*--------------------------------------------------------------------------------
         * Public Event Definitions
         *------------------------------------------------------------------------------*/
        #region Public Event Definitions
        /// <summary>
        /// Occurs when the OK button is clicked.
        /// </summary>
        public event EventHandler OkClick;
        /// <summary>
        /// Occurs when the cancel button is clicked.
        /// </summary>
        public event EventHandler CancelClick;
        #endregion


        /*--------------------------------------------------------------------------------
         * Constructor / Dispose / Destructor Methods
         *------------------------------------------------------------------------------*/
        #region Constructor / Dispose / Destructor Methods
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <remarks>
        /// This is the default constructor.
        /// </remarks>
        public OkCancelButtonPanel()
        {
            InitializeComponent();

            OkButton.Click +=new EventHandler(HandleOkClick);
            InternalCancelButton.Click += new EventHandler(HandleCancelClick);
        }
        /// <summary>
        /// Deallocates internally allocated objects.
        /// </summary>
        /// <param name="disposing">
        /// A value indicating whether the object is being disposed.
        /// </param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                OkButton.Click -= new EventHandler(HandleOkClick);
                InternalCancelButton.Click -= new EventHandler(HandleCancelClick);

                if (components != null)
                    components.Dispose();

                components = null;
            }
            base.Dispose(disposing);
        }
        #endregion

        /*--------------------------------------------------------------------------------
         * Public Properties
         *------------------------------------------------------------------------------*/
        #region Public Properties
        /// <summary>
        /// Gets or sets the caption displayed in the Cancel button.
        /// </summary>
        /// <value>
        /// The text displayed in the Cancel button.
        /// </value>
        [Browsable(true),
        DefaultValue("Cancel"),
        Description("Gets or sets the caption displayed in the Cancel button.")]
        public string CancelButtonText
        {
            get { return InternalCancelButton.Text; }
            set { InternalCancelButton.Text = value; }
        }
        /// <summary>
        /// Gets or sets the caption displayed in the OK button.
        /// </summary>
        /// <value>
        /// The text displayed in the OK button.
        /// </value>
        [Browsable(true),
        DefaultValue("OK"),
        Description("Gets or sets the caption displayed in the OK button.")]
        public string OkButtonText
        {
            get { return OkButton.Text; }
            set { OkButton.Text = value; }
        }
        /// <summary>
        /// Gets or sets a value indicating whether the Cancel button is visible.
        /// </summary>
        /// <value>
        /// <b>true</b> to show the cancel button; otherwise, <b>false</b>.
        /// </value>
        [Browsable(true),
        DefaultValue(true),
        Description("Gets or sets a value indicating whether the Cancel button is visible.")]
        public bool ShowCancelButton
        {
            get
            {
                return InternalCancelButton.Visible;
            }
            set
            {
                InternalCancelButton.Visible = value;
            }
        }
        /// <summary>
        /// Gets or sets a value indicating whether the OK button is visible.
        /// </summary>
        /// <value>
        /// <b>true</b> to show the OK button; otherwise, <b>false</b>.
        /// </value>
        [Browsable(true),
        DefaultValue(true),
        Description("Gets or sets a value indicating whether the OK button is visible")]
        public bool ShowOkButton
        {
            get
            {
                return OkButton.Visible;
            }
            set
            {
                OkButton.Visible = value;
            }
        }
        /// <summary>
        /// Gets or sets a value indicating whether the OK button is enabled.
        /// </summary>
        /// <value>
        /// <b>true</b> to enable the OK button; otherwise, <b>false</b>.
        /// </value>
        [Browsable(true),
        DefaultValue(true),
        Description("Gets or sets a value indicating whether the OK button is enabled.")]
        public bool EnableOkButton
        {
            get
            {
                return OkButton.Enabled;
            }
            set
            {
                OkButton.Enabled = value;
            }
        }
        /// <summary>
        /// Gets or sets the button control that is clicked when the user presses the ESC key.
        /// </summary>
        /// <value>
        /// An <see cref="IButtonControl"/> that represents the cancel button for the form.
        /// </value>
        /// <remarks>
        /// The cancel button for a form is the button control that is clicked whenever the user presses the ESC key. 
        /// The button assigned to this property must be an <see cref="IButtonControl"/> that is on the current 
        /// form or located within a container on the current form.
        /// </remarks>
        [DefaultValue((string)null), Description("The button control that is clicked whenever the user presses the ESC key.")]
        public IButtonControl CancelButton
        {
            get
            {
                return (IButtonControl)this.InternalCancelButton;
            }
            set
            {
            }
        }
        #endregion

        /*--------------------------------------------------------------------------------
         * Protected Event Methods
         *------------------------------------------------------------------------------*/
        #region Protected Event Methods
        /// <summary>
        /// Raises the <see cref="OkClick"/> event.
        /// </summary>
        /// <param name="e">
        /// An <see cref="EventArgs"/> event arguments instance.
        /// </param>
        public virtual void OnOkClick(EventArgs e)
        {
            if (OkClick != null)
                OkClick(this, e);
        }
        /// <summary>
        /// Raises the <see cref="CancelClick"/> event.
        /// </summary>
        /// <param name="e">
        /// An <see cref="EventArgs"/> event arguments instance.
        /// </param>
        public virtual void OnCancelClick(EventArgs e)
        {
            if (CancelClick != null)
                CancelClick(this, e);
        }
        #endregion

        /*--------------------------------------------------------------------------------
         * Private Event Handlers
         *------------------------------------------------------------------------------*/
        #region Private Event Handlers
        /// <summary>
        /// Handles the event when the OK button is clicked.
        /// </summary>
        /// <param name="sender">The object raising the event.</param>
        /// <param name="e">An <see cref="EventArgs"/> event arguments instance.</param>
        private void HandleOkClick(object sender, EventArgs e)
        {
            OnOkClick(e);
        }
        /// <summary>
        /// Handles the event when the Cancel button is clicked.
        /// </summary>
        /// <param name="sender">The object raising the event.</param>
        /// <param name="e">An <see cref="EventArgs"/> event arguments instance.</param>
        private void HandleCancelClick(object sender, EventArgs e)
        {
            OnCancelClick(e);
        }
        #endregion
    }
}
